<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<jsp:include page="../frame/header.jsp"></jsp:include>

<title>信息分类管理</title>
</head>

<body>

	<div class="container-fluid">
		<div class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">生活信息</a> <span class="divider">/</span></li>
					<li><a href="#">信息分类</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<i class="icon-edit"></i> 生活信息分类
					</h2>
					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<div class="tree well live">
						<ul>
							<li id="0"><span class="badge badge-important"><i
									class="icon-folder-open"></i> 生活信息分类</span> <a><font
									class="live_add_tip" onclick="addLiveSort(0)"><i class="icon-plus "></i> <font
										style="visibility: hidden"> 添加子分类</font> </font></a>

								<ul id="sorts_0">

								</ul>
							</li>
						</ul>
					</div>



				</div>
			</div>
			<!--/span-->


		</div>
		<!--/fluid-row-->

	</div>
	<!--/.fluid-container-->

	<jsp:include page="../frame/scripts.jsp"></jsp:include>
	<script type="text/javascript">
		$(document).ready(function(){
			var msg = "${message}";
			if(msg && msg.length > 0){
				alert(msg);
			}
			$.ajax({
				url:'<c:url value="/admin/live/sorts" />',
				dataType:'json',
				async:false,
				success:function(data){
					createSortTree(data);
				}
			})
			
			//生活信息分类 添加子分类内容提示
			$('.live_add_tip').hover(
				function(){
					$(this).find('font').css('visibility','visible');
				},
				function(){
					$(this).find('font').css('visibility','hidden');
				}
			);
			
			//增加连线样式
			$('.tree ul li ul li:not(":first")').css('border-top','1px dotted #dddddd');
			$('.tree li:last').css('border-bottom','1px dotted #dddddd');
		})
		
		function createSortTree(data){
			$.each(data,function(i,item){
				//生成节点
				createTreeNode(item);
				if(item.children.length > 0){
					//生成子节点
					createSortTree(item.children);
				}
			})
		}
		
		function createTreeNode(item){
			var parent = "sorts_"+item.sortParent;
			var $parent_ul = $("#"+parent);
			var str = '<li id='+item.sortId+'>';
			str += '<span><i class="icon-leaf"></i> '+item.sortName+'</span>';
			str += '<a>';
			str += '<font onclick="addLiveSort('+item.sortId+')" class="live_add_tip">';
			str += '<i class="icon-plus "></i> ';
			str += '<font style="visibility: hidden"> 添加子分类</font> ';
			str += '</font>';
			str += '</a>';
			
			str += '<p style="margin-top:2px" class="pull-right">';
			str += '&nbsp;&nbsp;&nbsp;&nbsp;';
			str += '<a onclick="editLiveSort('+item.sortId+')">编辑</a>';
			str += '&nbsp;&nbsp;&nbsp;&nbsp;';
			str += '<a onclick="delLiveSort('+item.sortId+')">删除</a>';
			str += '</p>';
			
			if(item.children.length > 0){
				str += '<ul id="sorts_'+item.sortId+'">';
				str += '</ul>';
			}
			
			str += '</li>';
			
			$parent_ul.append(str);
		}
		
		function addLiveSort(sortParent){
			window.location.href = '<c:url value="/admin/live/addChildSort"/>?sortParent='+sortParent;
		}
		
		function editLiveSort(sortId){
			window.location.href = '<c:url value="/admin/live/editChildSort"/>?sortId='+sortId;
		}
		
		function delLiveSort(sortId){
			if(confirm("该操作将删除该分类以及其下的所有子分类，确定要执行吗？")){
				window.location.href = '<c:url value="/admin/live/delChildSort"/>?sortId='+sortId;	
			}
			
		}
	</script>
	<script src="<c:url value="/resources/bootstrap/2.3.2/js/bootstrap-tree.js" />"></script>
</body>
</html>
